package com.woniu.atms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.atms.entity.G5Order;
import com.woniu.atms.entity.G5Passenger;
import com.woniu.atms.entity.G5User;
import com.woniu.atms.exception.UserNameExistException;
import com.woniu.atms.mapper.G5PassengerDao;
import com.woniu.atms.mapper.G5UserDao;
import com.woniu.atms.service.G5PassengerService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (G5Passenger)表服务实现类
 *
 * @author makejava
 * @since 2022-01-18 16:03:17
 */
@Service("g5PassengerService")
public class G5PassengerServiceImpl extends ServiceImpl<G5PassengerDao, G5Passenger> implements G5PassengerService {
    @Resource
    private G5PassengerDao g5PassengerDao;

    /**
     * 根据userid查找乘车人(is_exit=y)
     *
     * @param userId
     * @return
     */
    @Override
    public List<G5Passenger> findByUserIdY(Integer userId) {
        return g5PassengerDao.findByUserIdY(userId);
    }

    /**
     * 根据userid查找乘车人
     *
     * @param userId
     * @return
     */
    @Override
    public List<G5Passenger> findByUserId(Integer userId) {
        return g5PassengerDao.findByUserId(userId);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public G5Passenger queryById(Integer id) {
        return this.g5PassengerDao.queryById(id);
    }

    /**
     * 按条件分页查询
     *
     * @param pageNum   起始页
     * @param condition 筛选条件
     * @return 返回分页对象
     */
    @Override
    public PageInfo<G5Passenger> findByPage(Map<String, Object> condition, Integer pageNum, Integer pageSize) {
        //设置页码和每页记录数
        PageHelper.startPage(pageNum, pageSize);
        //获取集合
        List<G5Passenger> g5Passengers = g5PassengerDao.queryByCondition(condition);
        //创建分页对象
        PageInfo<G5Passenger> pageInfo = new PageInfo<>(g5Passengers);
        //返回分页对象
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param g5Passenger 实例对象
     * @return 实例对象
     */
    @Override
    public G5Passenger insert(G5Passenger g5Passenger) {
        g5Passenger.setIsOk("y");
        g5Passenger.setIsExit("y");
        this.g5PassengerDao.insert(g5Passenger);
        return g5Passenger;
    }

    /**
     * 修改数据
     *
     * @param g5Passenger 实例对象
     * @return 实例对象
     */
    @Override
    public G5Passenger update(G5Passenger g5Passenger) {
        this.g5PassengerDao.update(g5Passenger);
        return this.queryById(g5Passenger.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.g5PassengerDao.deleteById(id) > 0;
    }
}
